package com.itheima.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.itheima.crm.domain.Customer;

public interface ICustomerRepository extends JpaRepository<Customer, Integer> {
	
	//查询未关联定区的客户列表
	public List<Customer> findByFixedAreaIdIsNull();
	//查询关联定区的客户列表
	public List<Customer> findByFixedAreaId(String fixedAreaId);
	//客户关联分区
	@Query("update Customer set fixedAreaId = ? where id = ?")
	@Modifying
	public void updateFixedAreaId(String fixedAreaId,Integer id);
	//解除客户关联分区
	@Query("update Customer set fixedAreaId = null where fixedAreaId = ?")
	@Modifying
	public void clearFixedAreaId(String fixedAreaId);
	@Query("update Customer set type=1 where telephone= ?")
	@Modifying
	public void updateType(String telephone);

	public Customer findByTelephone(String telephone);
	//客户注册
	public Customer findByTelephoneAndPassword(String telephone, String password);
	//查询分区id
	@Query("select fixedAreaId from Customer where address=?")
	public String findfixedAreaIdByAddress(String address);
}
